<?php
require("cfg.php");
require("function.php");
$o_search_word=$_POST["search_word"];

$o_search_word=iconv("utf-8","gb2312",$o_search_word);
$o_search_word=ltrim($o_search_word);
$o_search_word=rtrim($o_search_word);
$tmp_search_word=explode(" ",$o_search_word);
$f_search_world="";
$ip=get_ip();
$sql="INSERT INTO `search_record` ( `id` , `search_word` , `user_name` , `ip` , `time` ) 
VALUES (
NULL , '$o_search_word', 'test_user', '$ip', NOW( ) 
);
";
mysql_query($sql);
if ($tmp_search_word[0]) {
		$tmp_search_word[0]=ltrim($tmp_search_word[0]);
		$tmp_search_word[0]=rtrim($tmp_search_word[0]);
		$tmp=$tmp_search_word[0];
		$f_search_world.=" `song_name` LIKE '%$tmp%'";
		
	}
for ($i=1;$i<count($tmp_search_word);$i++){

	if ($tmp_search_word[$i]) {
		$tmp_search_word[$i]=ltrim($tmp_search_word[$i]);
		$tmp_search_word[$i]=rtrim($tmp_search_word[$i]);
		$f_search_world.=" or `song_name` LIKE '%$tmp_search_word[$i]%'";
		
	}
	
	
}
$sql="SELECT DISTINCT `song_name`, `song_path` FROM `song_play_record` WHERE $f_search_world ;";
$query=mysql_query($sql);
while ($row = mysql_fetch_array($query)) {
	$tmp_song_name=iconv("gb2312","utf-8",$row['song_name']);
	$tmp_song_path=iconv("gb2312","utf-8",$row['song_path']);
	echo "<label><input type=\"checkbox\" name=\"$tmp_song_name\" value=\"$tmp_song_path\"/>$tmp_song_name</label>\r\n";
}
 
?>